package rickyGame.game.factory
{
	import ricky.game.Actor;
	import ricky.game.Actor2D;
	import ricky.game.graphic.Graphic;
	
	import rickyGame.model.config.*;
	import rickyGame.game.Building;
	import rickyGame.game.Goods;
	import rickyGame.game.Player;
	import rickyGame.game.graphic.DefaultScence;
	import rickyGame.model.config.Unit;

	/**
	 * 单元工厂类根据Unit数据创建相关游戏对象
	 */
	public class UnitFactory
	{
		public function UnitFactory()
		{
		}
		
		/**
		 * 根据单位数据创建游戏对象</br>
		 * u:Unit 单位配置数据</br>
		 * 
		 * @return Actor返回游戏对象
		 */
		public static function CreateActor(unit:Unit,level:int):Actor2D
		{
			if(unit is Unit)
			{
				var p:Player=new Player();
				p.isLock=true;
				p.active=false;
				Graphic(p.graphic).defaultScene=DefaultScence.deafultAnimScene;
				p.load(unit);
				p.loadProperty(level);
				return p;
			}else if(unit is Unit)
			{
				var b:Building=new Building();
				b.isLock=true;
				b.active=false;
				Graphic(b.graphic).defaultScene=DefaultScence.deafultAnimScene;
				b.load(unit);
				b.loadProperty(level);
				return b;
			}else if(unit is Unit)
			{
				var g:Goods=new Goods();
				g.isLock=true;
				g.active=false;
				Graphic(g.graphic).defaultScene=DefaultScence.deafultAnimScene;
				g.load(unit);
				g.loadProperty(level);
				return g;
			}
			return null;
		}
	}
}